//
//  HUD.swift
//  Performance
//
//  Created by topnet on 2021/12/21.
//

import UIKit
import MBProgressHUD

struct HUD {

    static func show() {
        DispatchQueue.main.async {
            guard let view = UIApplication.shared._keyWindow else { return }
            let hud = MBProgressHUD.showAdded(to: view, animated: true)
            hud.mode = .indeterminate
            hud.bezelView.blurEffectStyle = .light
        }
    }
    
    static func toast(_ status: String?) {
        DispatchQueue.main.async {
            guard let view = UIApplication.shared._keyWindow, let _status = status else { return }
            if MBProgressHUD.forView(view) != nil {
                MBProgressHUD.hide(for: view, animated: false)
            }
            let hud = MBProgressHUD.showAdded(to: view, animated: true)
            hud.mode = .text
            hud.detailsLabel.text = _status
            hud.minShowTime = 1.5
            hud.bezelView.blurEffectStyle = .dark
            hud.detailsLabel.textColor = .white
            hud.margin = 10
            hud.offset = CGPoint(x: 0, y: UIScreen.height/2-UIScreen.tabBarH - 20.adapter)
            hud.hide(animated: true, afterDelay: 1.5)
        }
    }
    
    static func dismiss(animated: Bool = true) {
        DispatchQueue.main.async {
            guard let view = UIApplication.shared._keyWindow else { return }
            MBProgressHUD.hide(for: view, animated: animated)
        }
    }
}

